package com.edgar.designpattern.combining.observer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Flock implements Quackable {

	List<Quackable> quackers = new ArrayList<Quackable>();

	public void add(Quackable quackable) {
		quackers.add(quackable);
	}

	@Override
	public void quack() {
		Iterator<Quackable> iterator = quackers.iterator();
		while (iterator.hasNext()) {
			Quackable quacker = (Quackable) iterator.next();
			quacker.quack();

		}

	}

	@Override
	public void registerObserver(Observer observer) {
		Iterator iterator = quackers.iterator();
		while (iterator.hasNext()) {
			Quackable duck = (Quackable) iterator.next();
			duck.registerObserver(observer);
		}
	}

	@Override
	public void notifyObservers() {

	}

	public String toString() {
		return "Flock of Ducks";
	}

}
